package com.sunlands.zlcx.usercenter.repository;

import com.sunlands.zlcx.usercenter.domain.LearnContentDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author shixiaopeng
 */
@Repository
public interface LearnContentRepository extends JpaRepository<LearnContentDO, Long>, JpaSpecificationExecutor<LearnContentDO> {

    List<LearnContentDO> findAllByUserIdAndIsDeleteOrderByStatusDescUpdateTimeDesc(Long userId, Integer isDelete);

    List<LearnContentDO> findAllByUserIdOrderByStatusDescUpdateTimeDesc(Long userId);

    Long countByUserIdAndIsDelete(Long userId, Integer isDelete);

    LearnContentDO findFirstByUserIdAndContentOrderByIdDesc(Long userId, String content);

    LearnContentDO findByUserIdAndModelAndStatusIn(Long userId, Integer model, List<Integer> statusList);

    LearnContentDO findByUserIdAndStatusIn(Long userId, List<Integer> statusList);

    @Modifying
    @Query(value = "update tz_learn_content set content =?3 where user_id = ?1 and content = ?2 ", nativeQuery = true)
    void updateContent(Long userId, String oldContent, String newContnet);

}
